
CC			= arm-linux-gcc
LD 			= arm-linux-ld
OBJCOPY		= arm-linux-objcopy
OBJDUMP		= arm-linux-objdump
# CFLAGS		= -mfloat-abi=soft	# 软浮点
# CFLAGS		= -mfpu=neon
CFLAGS		= -Wall -g



LIBPATH		= -L /home/enheng/ubuntu/bin/4.9.3/lib/gcc/arm-cortexa9-linux-gnueabihf/4.9.3 -lgcc
INCLUDEPATH	= -I./rtthread/3.0.3/include -I./USER -I./rtthread/3.0.3/bsp

TARGET		:= main

TOP_DIR 	:= $(shell pwd)
# SRC_DIRS 	:= $(shell ls -F | grep /$)
SRC_DIRS 	:= $(shell find $(TOP_DIR) -maxdepth 5 -type d)

C_SRCS		= $(foreach dir, $(SRC_DIRS), $(wildcard $(dir)/*.c))
# C_HEADS		= $(patsubst %.c, %.h, $(C_SRCS))
C_OBJS		= $(TOP_DIR)/start.o $(TOP_DIR)/rtthread/3.0.3/libcpu/arm/cortex-a9/context_rvds.o $(patsubst %.c, %.o, $(C_SRCS))

$(TARGET):$(C_OBJS)
	$(shell if [ ! -d $(TOP_DIR)/OBJ ]; then mkdir $(TOP_DIR)/OBJ; fi)
	$(LD) -T ld.lds $^ -o OBJ/$@.elf $(LIBPATH)
	$(OBJDUMP) -D OBJ/$@.elf > OBJ/$@.dis
	$(OBJCOPY) -I elf32-littlearm -Obinary OBJ/$@.elf OBJ/$@.bin

%.o:%.c
	$(CC) $(CFLAGS) $(INCLUDEPATH) -c $< -o $@ 

%.o:%.s
	$(CC) -c $< -o $@ 

.PHONY:clean
clean:
	rm -rf $(C_OBJS) OBJ/*.*


# echo:
# 	@echo $(TOP_DIR)
# 	@echo $(SRC_DIRS)
# 	@echo $(C_SRCS)
# 	@echo $(C_HEADS)
# 	@echo $(C_OBJS)
